#import "FlutterPluginNimrtcPlugin.h"
#import "NETSDemoP2PViewController.h"

static FlutterResult res;
@implementation FlutterPluginNimrtcPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
    
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"flutter_plugin_nimrtc"
            binaryMessenger:[registrar messenger]];
    FlutterPluginNimrtcPlugin* instance = [[FlutterPluginNimrtcPlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
    res = result;
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  }else if([@"call" isEqualToString:call.method]){
      [self callRtc: call.arguments];
  }else {
    result(FlutterMethodNotImplemented);
  }
}
//用户Id，随机生成
- (uint64_t)userId {
    return (10000 + arc4random() % (99999 - 10000));
}
- (void)callRtc:(NSDictionary*) args {
    NSLog(@"执行了void callRtc方法");
    NSLog(@"%@", args[@"roomId"]);
    NETSDemoP2PViewController *vc = [NETSDemoP2PViewController instanceWithRoomId:args[@"roomId"] appId:args[@"appId"] userId:self.userId];
    
//    [self.navigationController pushViewController:vc animated:YES];
    
    FlutterAppDelegate* delegate = (FlutterAppDelegate*)[[UIApplication sharedApplication]delegate];
    
     FlutterViewController* rootVC = (FlutterViewController*)delegate.window.rootViewController;
    
    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
    navi.navigationBarHidden = true;
    navi.modalPresentationStyle = UIModalPresentationFullScreen;
    navi.modalPresentationStyle = UIModalPresentationFullScreen;
    [rootVC presentViewController:navi animated:YES completion:nil];
}

@end
